
// const baseUrl = 'http://47.93.31.112:8083';
// const baseUrl = '';
const baseUrl = 'http://nxpz.natapp1.cc';
import store from '../store';

const request = (type, path, params) => {
    return new Promise((resolve, reject) => {
        uni.request({
            url: baseUrl + path, //仅为示例，并非真实接口地址。
            method: type,
            data: {...(params || {}), unionId: store.state?.userInfo?.unionId},
            success: (res) => {
                if (res.data && res.data.success && +res.data.code === 9200) {
                    resolve(res.data)
                }
                else {
                    uni.showToast({
                        title: res?.data?.msg || '网络错误' ,
                        icon: 'none'
                    });
                    reject(res);
                }
            },
            fail: (e) => {
                uni.showToast({
                    title: e?.data?.msg || '网络错误' ,
                    icon: 'none'
                });
                reject(e)
            }
        });
    })
}
export default {
    get: (path, params) => {
        return request('get', path, params);
    },
    post: (path, params) => {
        return request('post', path, params);
    }
}